# This file is part of BlackArch Linux ( https://www.blackarch.org/ ).
# See COPYING for license details.

pkgname=dcdetector
_gemname=$pkgname
pkgver=0.0.1.r52.g2e69244
pkgrel=4
pkgdesc='Spot all domain controllers in a Microsoft Active Directory environment. Find computer name, FQDN, and IP address(es) of all DCs.'
arch=('any')
groups=('blackarch' 'blackarch-networking' 'blackarch-recon' 'blackarch-windows')
url='https://github.com/noraj/DCDetector'
license=('MIT')
depends=('ruby' 'ruby-paint' 'ruby-docopt')
makedepends=('git')
options=(!emptydirs)
source=("git+https://github.com/noraj/$_gemname.git")
sha512sums=('SKIP')

pkgver() {
  cd $_gemname

  git describe --long --tags | sed 's/\([^-]*-g\)/r\1/;s/-/./g'
}

build() {
  cd $_gemname

  gem build "$pkgname.gemspec"
}

package() {
  cd $_gemname

  _gemdir="$(ruby -e'puts Gem.default_dir')"
  _release=$(gem build $pkgname.gemspec | grep Version | cut -d' ' -f4)

  gem install --ignore-dependencies --no-user-install --no-document \
    -i "$pkgdir/$_gemdir" -n "$pkgdir/usr/bin" "$_gemname-$_release.gem"

  rm "$pkgdir/$_gemdir/cache/$_gemname-$_release.gem"

  find "$pkgdir/$_gemdir/extensions/" -name *.so -delete

  install -Dm 644 "$pkgdir/$_gemdir/gems/$_gemname-$_release/LICENSE" \
    "$pkgdir/usr/share/licenses/$pkgname/LICENSE"
}

